package com.manage.competition.service.impl;

import com.manage.competition.entity.CompetitionReview;
import com.manage.competition.mapper.CompetitionReviewMapper;
import com.manage.competition.repository.CompetitionReviewRepository;
import com.manage.competition.service.ICompetitionReviewService;
import com.manage.competition.util.CurrentUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Create with IDEA
 *
 * @Author: gitee.com/KamisamaXX
 * @Date: Create in 21:36 2019/4/9
 * @Description:
 */
@Service
public class CompetitionReviewServiceImpl implements ICompetitionReviewService {

    @Autowired
    private CompetitionReviewRepository competitionReviewRepository;

    @Autowired
    private CompetitionReviewMapper competitionReviewMapper;

    @Override
    public CompetitionReview findByCompetitionIdAndUserId(long competitionId,long userId){
        return competitionReviewRepository.findByUserIdAndCompetitionId(userId,competitionId);
    }

    @Override
    public List<CompetitionReview> findByUserId(long userId){
        return competitionReviewRepository.findByUserId(userId);
    }

    @Override
    public int insert(CompetitionReview competitionReview) {
        competitionReview.setCreateUser(CurrentUserUtil.getCurrentUser().getUsername());
        competitionReview.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return competitionReviewMapper.insert(competitionReview);
    }

    @Override
    public List<CompetitionReview> findByCompetitionId(Long currentCompetition) {

        return competitionReviewRepository.findByCompetitionId(currentCompetition);
    }

    @Override
    public int delete(CompetitionReview competitionReview) {
        return competitionReviewMapper.deleteByPrimaryKey(competitionReview.getId());
    }
}
